<?php
namespace app\setting\controller;
use think\Request;
use app\common\controller\AdminBase;

class ApiAdminTool extends AdminBase
{
    public function urlPost(Request $request)
    {
        $postAddress = input('post.api');
        if (!$postAddress) {
            return jsonError('请先去设置推送的接口');
        }
        $url = input('post.url');
        if (!$url) {
            return jsonError('没有检测到你推送的页面地址');
        }
        $urls = explode(',',$url);
        if (is_array($urls)) {
            $api = $postAddress;
            $ch = curl_init();
            $options =  array(
                CURLOPT_URL => $api,
                CURLOPT_POST => true,
                CURLOPT_RETURNTRANSFER => true,
                CURLOPT_POSTFIELDS => implode("\n", $urls),
                CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
            );
            curl_setopt_array($ch, $options);
            $result = curl_exec($ch);
            curl_close($ch);
            return jsonSuccess($result);
        } else {
            return jsonError('数据格式错误');
        }
    }

    public function getPinyin()
    {
        $words = input('post.words');
        $type = input('post.type');
        if (!$words) {
            return jsonError('请输入内容');
        }
        $result = getPinyin($words);
        return jsonSuccess('',$result);
    }

}